<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="林湃滨的个人博客" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
     滨书
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/css/style.css">

  
<script src="/js/pace.min.js"></script>


  

  

<link rel="alternate" href="/atom.xml" title="滨书" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content">
      
<section class="cover">
    
  <div class="cover-frame">

    <div class="bg-box">
      <img src="/images/coverWLOP.jpg" alt="image frame" />
    </div>
      <iframe style="display: inline-block;float: right;margin: 10px;" frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=450 src="//music.163.com/outchain/player?type=0&id=4901576078&auto=1&height=430"></iframe>

    
    <div class="cover-inner text-center text-white">
      <h1><a href="/">滨书</a></h1>
      <div id="subtitle-box">
        
        <span id="subtitle"></span>
        
      </div>
      <div>
        
      </div>
    </div>
  </div>
  <div class="cover-learn-more">
    <a href="javascript:void(0)" class="anchor"><i class="ri-arrow-down-line"></i></a>
  </div>
</section>



<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js"></script>


<div id="main">
  <section class="outer">
  <article class="articles">
    
    
    
    
    <article id="post-Java/Java8中Stream常用方法" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/05/26/Java/Java8%E4%B8%ADStream%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/"
    >Java8中的Stream常用方法</a
  >
</h2>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/05/26/Java/Java8%E4%B8%ADStream%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95/" class="article-date">
  <time datetime="2020-05-26T14:41:35.000Z" itemprop="datePublished">2020-05-26</time>
</a>
      
      
      
      
    </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <p>Java8中，Stream数据流操作对集合操作做了极大的简化，学习了Stream，以后我们可以不用for循环就能对集合进行很多操作。</p>
<h2 id="Stream的初始化"><a href="#Stream的初始化" class="headerlink" title="Stream的初始化"></a>Stream的初始化</h2><p>Java中所有的Stream操作，都是针对流对象的，故使用Stream必须得初始化得到Stream类型对象：</p>
<ul>
<li><p>Stream初始化：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Stream stream = Stream.of(<span class="string">"a"</span>,<span class="string">"b"</span>,<span class="string">"c"</span>);</span><br></pre></td></tr></table></figure>



</li>
</ul>
<ul>
<li><p>数组转换为Stream：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">String [] strArray = <span class="keyword">new</span> String[]&#123;<span class="string">"a"</span>,<span class="string">"b"</span>,<span class="string">"c"</span>&#125;;</span><br><span class="line">Stream stream = Stream.of(strArray);</span><br><span class="line"><span class="comment">//或者</span></span><br><span class="line">Stream stream = Arrays.stream(strArray);</span><br></pre></td></tr></table></figure>



</li>
</ul>
<ul>
<li><p>集合对象转换为Stream：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">List&lt;String&gt; list = Arrays.asList(strArray);</span><br><span class="line">stream = list.stream();</span><br></pre></td></tr></table></figure>



</li>
</ul>
<h2 id="流操作"><a href="#流操作" class="headerlink" title="流操作"></a>流操作</h2><h3 id="1、遍历操作-map"><a href="#1、遍历操作-map" class="headerlink" title="1、遍历操作(map)"></a>1、遍历操作(map)</h3><p>使用map操作可以遍历集合中的每个对象，并对其操作；</p>
<p>map操作后，使用<code>.collect(Collectors.toList())</code>可以得到操作后的集合。</p>
<p>eg:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.1 遍历并转换为大写</span></span><br><span class="line">List&lt;String&gt; output = wordList.stream()</span><br><span class="line">    .map(String::toUpperCase)</span><br><span class="line">    .collect(Collectors.toList());</span><br><span class="line"></span><br><span class="line"><span class="comment">//1.2 对每个元素进行平方计算</span></span><br><span class="line">List&lt;Integer&gt; nums = Arrays.asList(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>);</span><br><span class="line">List&lt;Integer&gt; squareNums = nums.stream()</span><br><span class="line">    .map(n-&gt;n*n)</span><br><span class="line">    .collect(Collectors.toList());</span><br></pre></td></tr></table></figure>





<h3 id="2、过滤操作-filter"><a href="#2、过滤操作-filter" class="headerlink" title="2、过滤操作(filter)"></a>2、过滤操作(filter)</h3><p>利用filter可以对Stream中的数据元素进行过滤，通过过滤的元素会保留下来生成一个新的Stream。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">List&lt;String&gt; filterLists = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">filterLists.add(<span class="string">""</span>);</span><br><span class="line">filterLists.add(<span class="string">"a"</span>);</span><br><span class="line">filterLists.add(<span class="string">"b"</span>);</span><br><span class="line">List afterFilterLists = filterLists.stream()</span><br><span class="line">    .filter(s-&gt;!s.isEmpty())</span><br><span class="line">    .collect(Collectors.toList());</span><br></pre></td></tr></table></figure>





<h3 id="3、循环操作-forEach"><a href="#3、循环操作-forEach" class="headerlink" title="3、循环操作(forEach)"></a>3、循环操作(forEach)</h3><p>对Stream中的每个对象进行<strong>自定义操作</strong>，可使用forEach：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">List&lt;String&gt; forEachLists = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line"></span><br><span class="line">forEachLists.add(<span class="string">"a"</span>);</span><br><span class="line">forEachLists.add(<span class="string">"b"</span>);</span><br><span class="line">forEachLists.add(<span class="string">"c"</span>);</span><br><span class="line"></span><br><span class="line">forEachLists.stream().forEach(s-&gt;System.out.println(s));</span><br></pre></td></tr></table></figure>





<h3 id="4、返回特定结果集合-limit-skip"><a href="#4、返回特定结果集合-limit-skip" class="headerlink" title="4、返回特定结果集合(limit/skip)"></a>4、返回特定结果集合(limit/skip)</h3><ul>
<li>limit返回Stream的前面n个元素</li>
<li>skip则是跳过前n个元素</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">List&lt;String&gt; forEachLists = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line"></span><br><span class="line">forEachLists.add(<span class="string">"a"</span>);</span><br><span class="line">forEachLists.add(<span class="string">"b"</span>);</span><br><span class="line">forEachLists.add(<span class="string">"c"</span>);</span><br><span class="line">forEachLists.add(<span class="string">"d"</span>);</span><br><span class="line">forEachLists.add(<span class="string">"e"</span>);</span><br><span class="line">forEachLists.add(<span class="string">"f"</span>);</span><br><span class="line"></span><br><span class="line">List&lt;String&gt; limitLists = forEachLists.stream()</span><br><span class="line">    .skip(<span class="number">2</span>)</span><br><span class="line">    .limit(<span class="number">3</span>)</span><br><span class="line">    .collect(Collectors.toList());</span><br><span class="line"><span class="comment">//先跳过前2个元素</span></span><br><span class="line"><span class="comment">//再取Stream剩余元素的前3，生成新的Stream并返回</span></span><br></pre></td></tr></table></figure>





<h3 id="5、排序-sort-min-max-distinct"><a href="#5、排序-sort-min-max-distinct" class="headerlink" title="5、排序(sort/min/max/distinct)"></a>5、排序(sort/min/max/distinct)</h3><ul>
<li><p>sort可以对集合中的所有元素进行排序。</p>
</li>
<li><p>max，min可以找出Stream中最大/最小的元素。</p>
</li>
<li><p>distinct可以寻找出不重复的元素。</p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.对集合排序</span></span><br><span class="line">List&lt;Integer&gt; sortLists = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">sortLists.add(<span class="number">1</span>);</span><br><span class="line">sortLists.add(<span class="number">4</span>);</span><br><span class="line">sortLists.add(<span class="number">6</span>);</span><br><span class="line">sortLists.add(<span class="number">3</span>);</span><br><span class="line">sortLists.add(<span class="number">2</span>);</span><br><span class="line"></span><br><span class="line">List&lt;Integer&gt; afterSortLists = sortLists.stream()</span><br><span class="line">    .sorted((In1,In2)-&gt;In1-In2)</span><br><span class="line">    .collect(Collectors.toList());</span><br><span class="line"></span><br><span class="line"><span class="comment">//2.获取最大长度的元素</span></span><br><span class="line">List&lt;String&gt; maxLists = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">maxLists.add(<span class="string">"a"</span>);</span><br><span class="line">maxLists.add(<span class="string">"b"</span>);</span><br><span class="line">maxLists.add(<span class="string">"c"</span>);</span><br><span class="line">maxLists.add(<span class="string">"d"</span>);</span><br><span class="line">maxLists.add(<span class="string">"e"</span>);</span><br><span class="line">maxLists.add(<span class="string">"f"</span>);</span><br><span class="line">maxLists.add(<span class="string">"hahaha"</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> maxLength = maxLists.stream()  <span class="comment">//获取列表中最长元素的长度</span></span><br><span class="line">    .mapToInt(s-&gt;s.length())</span><br><span class="line">    .max().getAsInt();</span><br><span class="line"></span><br><span class="line"><span class="comment">//3.对集合进行查重</span></span><br><span class="line">List&lt;String&gt; distinctList = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">distinctList.add(<span class="string">"a"</span>);</span><br><span class="line">distinctList.add(<span class="string">"a"</span>);</span><br><span class="line">distinctList.add(<span class="string">"c"</span>);</span><br><span class="line">distinctList.add(<span class="string">"d"</span>);</span><br><span class="line"></span><br><span class="line">List&lt;String&gt; afterDistinctList = distinctList.stream()</span><br><span class="line">    .distinct()<span class="comment">//去重</span></span><br><span class="line">    .collect(Collectors.toList())</span><br></pre></td></tr></table></figure>





<h3 id="6、匹配-Match相关"><a href="#6、匹配-Match相关" class="headerlink" title="6、匹配(Match相关)"></a>6、匹配(Match相关)</h3><p>有时，我们需要判断集合中是否全部满足条件，或判断集合中是否存在满足条件的元素，此时就可以使用match方法：</p>
<ul>
<li>allMatch：Stream中全部元素扶额传入的predicate，返回true；</li>
<li>anyMatch：Stream中任何一个元素符合传入的predicate，返回true；</li>
<li>noneMatch：Stream中不存在元素符合传入的predicate，返回true；</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">List&lt;String&gt; matchList = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">matchList.add(<span class="string">"a"</span>);</span><br><span class="line">matchList.add(<span class="string">""</span>);</span><br><span class="line">matchList.add(<span class="string">"a"</span>);</span><br><span class="line">matchList.add(<span class="string">"c"</span>);</span><br><span class="line">matchList.add(<span class="string">"d"</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//1.判断集合中是否存在“c”的字符串元素</span></span><br><span class="line">Boolean isExits = matchList.stream()</span><br><span class="line">    .anyMatch(s-&gt;s.equals(<span class="string">"c"</span>));</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//2.判断集合中是否全不为空</span></span><br><span class="line">Boolean isAllNull = matchList.stream()</span><br><span class="line">    .allMatch(s-&gt;s.isNotEmpty());</span><br><span class="line"></span><br><span class="line">Boolean isAllNull2 = matchList.stream()</span><br><span class="line">    .noneMatch(s-&gt;s.isEmpty());</span><br></pre></td></tr></table></figure>




      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java/" rel="tag">Java</a></li></ul>


    </footer>

  </div>

  

  
  
  

  

</article>
    
    <article id="post-毕业档案挂靠、落户深圳问题" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/05/26/%E6%AF%95%E4%B8%9A%E6%A1%A3%E6%A1%88%E6%8C%82%E9%9D%A0%E3%80%81%E8%90%BD%E6%88%B7%E6%B7%B1%E5%9C%B3%E9%97%AE%E9%A2%98/"
    >毕业档案挂靠、落户深圳问题</a
  >
</h2>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/05/26/%E6%AF%95%E4%B8%9A%E6%A1%A3%E6%A1%88%E6%8C%82%E9%9D%A0%E3%80%81%E8%90%BD%E6%88%B7%E6%B7%B1%E5%9C%B3%E9%97%AE%E9%A2%98/" class="article-date">
  <time datetime="2020-05-26T14:08:40.000Z" itemprop="datePublished">2020-05-26</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E6%AF%95%E4%B8%9A%E7%9B%B8%E5%85%B3/">毕业相关</a>
  </div>

      
      
      
    </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h2 id="档案派遣挂靠、落户相关问题"><a href="#档案派遣挂靠、落户相关问题" class="headerlink" title="档案派遣挂靠、落户相关问题"></a>档案派遣挂靠、落户相关问题</h2><blockquote>
<p>本人人是在广州大学就读，入职公司在深圳。问题回答信息仅供参考</p>
</blockquote>
<ul>
<li><p>毕业档案到底是什么？</p>
<p>档案是我们过去在高中和大学的生活学习记录，包括在校表现、党团关系、体检表等等。大学入学时档案从高中转移到学校，毕业前就需要把档案进行迁移，大家一般是把档案挂靠在省人才。</p>
</li>
</ul>
<ul>
<li><p>毕业后档案去向哪里？</p>
<p>档案是比较机密文件，所以只有受政府监控的单位和部门才有资格保管:</p>
<ul>
<li>是学校（毕业后需要迁出去）；</li>
<li>打回生源地；</li>
<li>部分国企或事业单位；</li>
<li>人才市场保管（省人才是省级行政单位机构，本省有档案审批和保管权）。</li>
</ul>
</li>
</ul>
<ul>
<li><p>档案挂靠有什么作用？</p>
<p>档案挂靠省人才可免费入户广州、档案永久保管、党团籍保管、转正定级、工龄持续累计、代办五险一金、免小孩入学赞助费等。</p>
</li>
</ul>
<ul>
<li><p>毕业后如果档案挂靠在学校，会对以后找工作造成什么不方便吗？</p>
<p>学校存放的是<strong>学籍档案</strong>，人才市场是<strong>人事档案</strong>，而工龄、社保、工作证明等以人事档案为主。</p>
<blockquote>
<p>学籍档案是无法计算工龄、转正定级、职称评定和工作证明的。</p>
<p>另外学校是暂存，迟早都要迁移出来，而且后面取消暂缓和走流程也比较麻烦。</p>
</blockquote>
</li>
</ul>
<ul>
<li><p>打回生源地和省人才市场有什么区别，正常就业选择哪个比较好？</p>
<p>打回生源地是<strong>不建议选项</strong>，请谨慎选择：</p>
<ol>
<li>后面改派、工作调档比较麻烦</li>
<li>失去转正定级、职称评定资格</li>
<li>选择回生源地意味着放弃广州户口。</li>
</ol>
</li>
</ul>
<ul>
<li><p>把档案放在人才中心需要保管费吗？</p>
<p>每年的档案保管费已经取消，只收取一次性统一服务费，终身挂靠和永久入户。</p>
</li>
</ul>
<ul>
<li><p>只要毕业两年内没有购买社保记录就是应届生身份，可以这样理解吗？</p>
<p>是的。</p>
</li>
</ul>
<ul>
<li><p>怎样才可以拿到补贴？只要存到人才市场就可以了吗？</p>
<p>领取补贴，需要先处理好档案挂靠，才能申请</p>
</li>
</ul>
<ul>
<li><p>深圳的档案挂靠和户口问题</p>
<p>深圳是档案和户口不分离。</p>
</li>
</ul>
<ul>
<li><p>目前申请了档案暂不派遣，会影响之后的档案改派到深圳以及落户深圳吗？</p>
<p>暂不派遣的同学，可以在6月3日(学校发布时间）前处理好三方和接受函，可以改到人才市场</p>
</li>
</ul>
<ul>
<li><p>三方协议已经填了回生源地，也可以进行改派吗？</p>
<p>家里没拆迁，没有农村户口福利，不建议迁回去，后面改派和其他方面不方便。</p>
</li>
</ul>
<ul>
<li><p>我把档案存学校可以存多久呢。可以保留多久的应届生条件？</p>
<p>学校暂存2年，但是这两年如果你工作证明、升职证明、社保住房公积金等是不可以处理的。</p>
<blockquote>
<p>没什么事建议不要放在学校，对工作不方便，后面还要改派调出来。迟早都是要出来，后面流程还更麻烦和费神</p>
</blockquote>
</li>
</ul>
<ul>
<li><p>牵档案过去深圳需要先把档案牵过去才能牵户口吗？</p>
<p>深圳的需要先处理档案申请，然后才可以入户。档案申请后，一般毕业后1-3个月内入户深圳</p>
</li>
</ul>

      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%A1%A3%E6%A1%88/" rel="tag">档案</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E8%90%BD%E6%88%B7/" rel="tag">落户</a></li></ul>


    </footer>

  </div>

  

  
  
  

  

</article>
    
    <article id="post-Java/Java8中的Stream之函数式接口" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/05/25/Java/Java8%E4%B8%AD%E7%9A%84Stream%E4%B9%8B%E5%87%BD%E6%95%B0%E5%BC%8F%E6%8E%A5%E5%8F%A3/"
    >Java8中的Stream之函数式接口</a
  >
</h2>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/05/25/Java/Java8%E4%B8%AD%E7%9A%84Stream%E4%B9%8B%E5%87%BD%E6%95%B0%E5%BC%8F%E6%8E%A5%E5%8F%A3/" class="article-date">
  <time datetime="2020-05-25T14:41:35.000Z" itemprop="datePublished">2020-05-25</time>
</a>
      
      
      
      
    </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h1 id="玩转Java8的-Stream-之函数式接口"><a href="#玩转Java8的-Stream-之函数式接口" class="headerlink" title="玩转Java8的 Stream 之函数式接口"></a>玩转Java8的 Stream 之函数式接口</h1><p>​    函数式接口是伴随着Stream的诞生而出现的，Java8的Stream 作为函数式编程的一种具体实现，开发者无需关注怎么做，只需知道要做什么，各种操作符配合简洁明了的函数式接口给开发者带来了简单快速处理数据的体验。</p>
<h3 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h3><p>简单地说，函数式接口就是只有一个抽象函数的接口。</p>
<p>为了使得函数式接口的定义更加规范，Java8中提供了@FunctionalInterface注解告诉编译器在编译器去检查函数式接口的合法性，以便在编译器在编译器出错时给出提示。</p>
<p>为了更加规范定义函数接口，给出如下函数式接口定义规则：</p>
<ul>
<li>有且仅有一个抽象函数；</li>
<li>必须要@FunctionalInterface注解；</li>
<li>允许存在默认方法；</li>
</ul>
<p>其实，我们常用到的Runnable接口，便是一个函数式接口：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FunctionalInterface</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">Runnable</span> </span>&#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * When an object implementing interface &lt;code&gt;Runnable&lt;/code&gt; is used</span></span><br><span class="line"><span class="comment">     * to create a thread, starting the thread causes the object's</span></span><br><span class="line"><span class="comment">     * &lt;code&gt;run&lt;/code&gt; method to be called in that separately executing</span></span><br><span class="line"><span class="comment">     * thread.</span></span><br><span class="line"><span class="comment">     * &lt;p&gt;</span></span><br><span class="line"><span class="comment">     * The general contract of the method &lt;code&gt;run&lt;/code&gt; is that it may</span></span><br><span class="line"><span class="comment">     * take any action whatsoever.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@see</span>     java.lang.Thread#run()</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<blockquote>
<p>以前使用匿名内部类实现线程的执行体：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> Thread(<span class="keyword">new</span> Runable()&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">()</span></span>&#123;</span><br><span class="line">        System.out.println(<span class="string">"Hello FunctionalInterface"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;).start();</span><br></pre></td></tr></table></figure>

<p>使用Lambda表达式简化代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> Thread(()-&gt;&#123;</span><br><span class="line">    System.out.println(<span class="string">"hello FunctionalInterface"</span>);</span><br><span class="line">&#125;).start();</span><br></pre></td></tr></table></figure>


</blockquote>
<p>Java 8 中util.function包下的函数式接口大体分为如下几类：</p>
<ul>
<li>Consumer 消费接口</li>
<li>Function 功能接口</li>
<li>Operator 操作接口</li>
<li>Predicate 断言接口</li>
<li>Supplier 生产接口</li>
</ul>
<h3 id="详细介绍"><a href="#详细介绍" class="headerlink" title="详细介绍"></a>详细介绍</h3><h4 id="Consumer"><a href="#Consumer" class="headerlink" title="Consumer"></a>Consumer</h4><p>消费者接口，用于消费数据</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FunctionalInterface</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">Consumer</span>&lt;<span class="title">T</span>&gt; </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Performs this operation on the given argument.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> t the input argument</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">accept</span><span class="params">(T t)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Returns a composed &#123;<span class="doctag">@code</span> Consumer&#125; that performs, in sequence, this</span></span><br><span class="line"><span class="comment">     * operation followed by the &#123;<span class="doctag">@code</span> after&#125; operation. If performing either</span></span><br><span class="line"><span class="comment">     * operation throws an exception, it is relayed to the caller of the</span></span><br><span class="line"><span class="comment">     * composed operation.  If performing this operation throws an exception,</span></span><br><span class="line"><span class="comment">     * the &#123;<span class="doctag">@code</span> after&#125; operation will not be performed.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> after the operation to perform after this operation</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a composed &#123;<span class="doctag">@code</span> Consumer&#125; that performs in sequence this</span></span><br><span class="line"><span class="comment">     * operation followed by the &#123;<span class="doctag">@code</span> after&#125; operation</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> NullPointerException if &#123;<span class="doctag">@code</span> after&#125; is null</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">default</span> Consumer&lt;T&gt; <span class="title">andThen</span><span class="params">(Consumer&lt;? <span class="keyword">super</span> T&gt; after)</span> </span>&#123;</span><br><span class="line">        Objects.requireNonNull(after);</span><br><span class="line">        <span class="keyword">return</span> (T t) -&gt; &#123; accept(t); after.accept(t); &#125;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>Consumer接口中的accept抽象方法接收一个变量。在使用这个函数式接口时，给我们提供了数据，我们只需要接收使用便可。</p>
<p>andThen是一个默认方法，接收一个Consumer类型，只要我们一直使用andThen，就可以多次使用一个数据。</p>
<h4 id="Function"><a href="#Function" class="headerlink" title="Function"></a>Function</h4><p>Function提供的是一种转换功能。</p>
<blockquote>
<p>比如空调，给我们带来清凉，但它需要电能；对于我们来说，空调把电能转换为了室内低温.</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FunctionalInterface</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">Function</span>&lt;<span class="title">T</span>,<span class="title">R</span>&gt;</span>&#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Applies this function to the given argument.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> t the function argument</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> the function result</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function">R <span class="title">apply</span><span class="params">(T t)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Returns a composed function that first applies the &#123;<span class="doctag">@code</span> before&#125;</span></span><br><span class="line"><span class="comment">     * function to its input, and then applies this function to the result.</span></span><br><span class="line"><span class="comment">     * If evaluation of either function throws an exception, it is relayed to</span></span><br><span class="line"><span class="comment">     * the caller of the composed function.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> &lt;V&gt; the type of input to the &#123;<span class="doctag">@code</span> before&#125; function, and to the</span></span><br><span class="line"><span class="comment">     *           composed function</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> before the function to apply before this function is applied</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a composed function that first applies the &#123;<span class="doctag">@code</span> before&#125;</span></span><br><span class="line"><span class="comment">     * function and then applies this function</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> NullPointerException if before is null</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@see</span> #andThen(Function)</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">default</span> &lt;V&gt; <span class="function">Function&lt;V, R&gt; <span class="title">compose</span><span class="params">(Function&lt;? <span class="keyword">super</span> V, ? extends T&gt; before)</span> </span>&#123;</span><br><span class="line">        Objects.requireNonNull(before);</span><br><span class="line">        <span class="keyword">return</span> (V v) -&gt; apply(before.apply(v));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Returns a composed function that first applies this function to</span></span><br><span class="line"><span class="comment">     * its input, and then applies the &#123;<span class="doctag">@code</span> after&#125; function to the result.</span></span><br><span class="line"><span class="comment">     * If evaluation of either function throws an exception, it is relayed to</span></span><br><span class="line"><span class="comment">     * the caller of the composed function.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> &lt;V&gt; the type of output of the &#123;<span class="doctag">@code</span> after&#125; function, and of the</span></span><br><span class="line"><span class="comment">     *           composed function</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> after the function to apply after this function is applied</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a composed function that first applies this function and then</span></span><br><span class="line"><span class="comment">     * applies the &#123;<span class="doctag">@code</span> after&#125; function</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> NullPointerException if after is null</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@see</span> #compose(Function)</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">default</span> &lt;V&gt; <span class="function">Function&lt;T, V&gt; <span class="title">andThen</span><span class="params">(Function&lt;? <span class="keyword">super</span> R, ? extends V&gt; after)</span> </span>&#123;</span><br><span class="line">        Objects.requireNonNull(after);</span><br><span class="line">        <span class="keyword">return</span> (T t) -&gt; after.apply(apply(t));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Returns a function that always returns its input argument.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> &lt;T&gt; the type of the input and output objects to the function</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a function that always returns its input argument</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">static</span> &lt;T&gt; <span class="function">Function&lt;T, T&gt; <span class="title">identity</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> t -&gt; t;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>Function接口主要是apply函数。apply函数接收T类型，返回R类型数据，即将T类型的数据转换为R类型的数据，提供了compose、andThen、identity三个默认方法。</p>
<ul>
<li>compose 接受一个Function，andThen也同样接受一个Function，这里的andThen 与Consumer 的andThen 类似，在apply之后在apply一遍，compose 则与之相反，在apply之前先apply（这两个apply具体处理内容一般是不同的）</li>
<li>identity 起到了类似海关的作用，外国人想要运货进来，总得交点税吧，然后货物才能安全进入中国市场，当然了想不想收税还是你说了算的:。</li>
</ul>
<h4 id="Operator"><a href="#Operator" class="headerlink" title="Operator"></a>Operator</h4><p>可以简单理解成算术中的各种运算操作，当然不仅仅是运算这么简单，因为它只定义了运算这个定义，但至于运算成什么样你说了算。</p>
<p>由于没有最基础的Operator，这里将通过<code>BinaryOperator</code>、<code>IntBinaryOperator</code>来理解Operator 函数式接口：</p>
<ul>
<li><p>IntBinaryOperator</p>
<p>Int类型的二元操作。这个接口除了加减乘除操作。定义如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FunctionalInterface</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">IntBinaryOperator</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Applies this operator to the given operands.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> left the first operand</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> right the second operand</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> the operator result</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">int</span> <span class="title">applyAsInt</span><span class="params">(<span class="keyword">int</span> left, <span class="keyword">int</span> right)</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>IntBinaryOperator接口中只有一个applyAsInt方法，接收两个int类型的参数，返回int类型结果。着与Function接口的apply些许相像，但限定了只能为int类型。</p>
</li>
</ul>
<ul>
<li><p>BinaryOperator</p>
<p>二元操作，它和<code>IntBinaryOperator</code>之间并没有关系，只是看起来像。不过两者之间在功能上有些许相似之处：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FunctionalInterface</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">BinaryOperator</span>&lt;<span class="title">T</span>&gt; <span class="keyword">extends</span> <span class="title">BiFunction</span>&lt;<span class="title">T</span>,<span class="title">T</span>,<span class="title">T</span>&gt; </span>&#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Returns a &#123;<span class="doctag">@link</span> BinaryOperator&#125; which returns the lesser of two elements</span></span><br><span class="line"><span class="comment">     * according to the specified &#123;<span class="doctag">@code</span> Comparator&#125;.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> &lt;T&gt; the type of the input arguments of the comparator</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> comparator a &#123;<span class="doctag">@code</span> Comparator&#125; for comparing the two values</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a &#123;<span class="doctag">@code</span> BinaryOperator&#125; which returns the lesser of its operands,</span></span><br><span class="line"><span class="comment">     *         according to the supplied &#123;<span class="doctag">@code</span> Comparator&#125;</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> NullPointerException if the argument is null</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> &lt;T&gt; <span class="function">BinaryOperator&lt;T&gt; <span class="title">minBy</span><span class="params">(Comparator&lt;? <span class="keyword">super</span> T&gt; comparator)</span> </span>&#123;</span><br><span class="line">        Objects.requireNonNull(comparator);</span><br><span class="line">        <span class="keyword">return</span> (a, b) -&gt; comparator.compare(a, b) &lt;= <span class="number">0</span> ? a : b;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Returns a &#123;<span class="doctag">@link</span> BinaryOperator&#125; which returns the greater of two elements</span></span><br><span class="line"><span class="comment">     * according to the specified &#123;<span class="doctag">@code</span> Comparator&#125;.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> &lt;T&gt; the type of the input arguments of the comparator</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> comparator a &#123;<span class="doctag">@code</span> Comparator&#125; for comparing the two values</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a &#123;<span class="doctag">@code</span> BinaryOperator&#125; which returns the greater of its operands,</span></span><br><span class="line"><span class="comment">     *         according to the supplied &#123;<span class="doctag">@code</span> Comparator&#125;</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> NullPointerException if the argument is null</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> &lt;T&gt; <span class="function">BinaryOperator&lt;T&gt; <span class="title">maxBy</span><span class="params">(Comparator&lt;? <span class="keyword">super</span> T&gt; comparator)</span> </span>&#123;</span><br><span class="line">        Objects.requireNonNull(comparator);</span><br><span class="line">        <span class="keyword">return</span> (a, b) -&gt; comparator.compare(a, b) &gt;= <span class="number">0</span> ? a : b;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>BinaryOperator 是 BiFunction 的子类，而IntBinaryOperator没有父类， 是从石头里蹦出来的；BinaryOperator 自身定义了minBy、maxBy默认方法，并且参数都是Comparator，就是根据传入的比较器的比较规则找出最小最大的数据。</p>
</li>
</ul>
<h4 id="Predicate"><a href="#Predicate" class="headerlink" title="Predicate"></a>Predicate</h4><p>对输入的数据根据某个标准进行评判，最终返回boolean值：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FunctionalInterface</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">Predicate</span>&lt;<span class="title">T</span>&gt; </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Evaluates this predicate on the given argument.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> t the input argument</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> &#123;<span class="doctag">@code</span> true&#125; if the input argument matches the predicate,</span></span><br><span class="line"><span class="comment">     * otherwise &#123;<span class="doctag">@code</span> false&#125;</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">boolean</span> <span class="title">test</span><span class="params">(T t)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Returns a composed predicate that represents a short-circuiting logical</span></span><br><span class="line"><span class="comment">     * AND of this predicate and another.  When evaluating the composed</span></span><br><span class="line"><span class="comment">     * predicate, if this predicate is &#123;<span class="doctag">@code</span> false&#125;, then the &#123;<span class="doctag">@code</span> other&#125;</span></span><br><span class="line"><span class="comment">     * predicate is not evaluated.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * &lt;p&gt;Any exceptions thrown during evaluation of either predicate are relayed</span></span><br><span class="line"><span class="comment">     * to the caller; if evaluation of this predicate throws an exception, the</span></span><br><span class="line"><span class="comment">     * &#123;<span class="doctag">@code</span> other&#125; predicate will not be evaluated.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> other a predicate that will be logically-ANDed with this</span></span><br><span class="line"><span class="comment">     *              predicate</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a composed predicate that represents the short-circuiting logical</span></span><br><span class="line"><span class="comment">     * AND of this predicate and the &#123;<span class="doctag">@code</span> other&#125; predicate</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> NullPointerException if other is null</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">default</span> Predicate&lt;T&gt; <span class="title">and</span><span class="params">(Predicate&lt;? <span class="keyword">super</span> T&gt; other)</span> </span>&#123;</span><br><span class="line">        Objects.requireNonNull(other);</span><br><span class="line">        <span class="keyword">return</span> (t) -&gt; test(t) &amp;&amp; other.test(t);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Returns a predicate that represents the logical negation of this</span></span><br><span class="line"><span class="comment">     * predicate.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a predicate that represents the logical negation of this</span></span><br><span class="line"><span class="comment">     * predicate</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">default</span> Predicate&lt;T&gt; <span class="title">negate</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> (t) -&gt; !test(t);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Returns a composed predicate that represents a short-circuiting logical</span></span><br><span class="line"><span class="comment">     * OR of this predicate and another.  When evaluating the composed</span></span><br><span class="line"><span class="comment">     * predicate, if this predicate is &#123;<span class="doctag">@code</span> true&#125;, then the &#123;<span class="doctag">@code</span> other&#125;</span></span><br><span class="line"><span class="comment">     * predicate is not evaluated.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * &lt;p&gt;Any exceptions thrown during evaluation of either predicate are relayed</span></span><br><span class="line"><span class="comment">     * to the caller; if evaluation of this predicate throws an exception, the</span></span><br><span class="line"><span class="comment">     * &#123;<span class="doctag">@code</span> other&#125; predicate will not be evaluated.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> other a predicate that will be logically-ORed with this</span></span><br><span class="line"><span class="comment">     *              predicate</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a composed predicate that represents the short-circuiting logical</span></span><br><span class="line"><span class="comment">     * OR of this predicate and the &#123;<span class="doctag">@code</span> other&#125; predicate</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> NullPointerException if other is null</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">default</span> Predicate&lt;T&gt; <span class="title">or</span><span class="params">(Predicate&lt;? <span class="keyword">super</span> T&gt; other)</span> </span>&#123;</span><br><span class="line">        Objects.requireNonNull(other);</span><br><span class="line">        <span class="keyword">return</span> (t) -&gt; test(t) || other.test(t);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Returns a predicate that tests if two arguments are equal according</span></span><br><span class="line"><span class="comment">     * to &#123;<span class="doctag">@link</span> Objects#equals(Object, Object)&#125;.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> &lt;T&gt; the type of arguments to the predicate</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> targetRef the object reference with which to compare for equality,</span></span><br><span class="line"><span class="comment">     *               which may be &#123;<span class="doctag">@code</span> null&#125;</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a predicate that tests if two arguments are equal according</span></span><br><span class="line"><span class="comment">     * to &#123;<span class="doctag">@link</span> Objects#equals(Object, Object)&#125;</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">static</span> &lt;T&gt; <span class="function">Predicate&lt;T&gt; <span class="title">isEqual</span><span class="params">(Object targetRef)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> (<span class="keyword">null</span> == targetRef)</span><br><span class="line">                ? Objects::isNull</span><br><span class="line">                : object -&gt; targetRef.equals(object);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>Predicate的test 接收T类型的数据，返回 boolean 类型，即对数据进行某种规则的评判，如果符合则返回true，否则返回false；Predicate接口还提供了 and（并）、negate（取反）、or（或），与 取反 或等，isEqual 判断两个参数是否相等等默认函数。</p>
<h4 id="Supplier"><a href="#Supplier" class="headerlink" title="Supplier"></a>Supplier</h4><p>生产、提供数据：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@FunctionalInterface</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">Supplier</span>&lt;<span class="title">T</span>&gt; </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Gets a result.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> a result</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function">T <span class="title">get</span><span class="params">()</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>非常easy，get方法返回一个T类数据，可以提供重复的数据，或者随机种子都可以，就这么简单。</p>
<h3 id="实际应用"><a href="#实际应用" class="headerlink" title="实际应用"></a>实际应用</h3><h4 id="Consumer-1"><a href="#Consumer-1" class="headerlink" title="Consumer"></a>Consumer</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">      Stream.of(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>)</span><br><span class="line">                .forEach(o -&gt; System.out.println(o)); <span class="comment">//输出1，2，3，4，5，6</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="Function-1"><a href="#Function-1" class="headerlink" title="Function"></a>Function</h4><ol>
<li><p>转换，将集合中的字符串转为对应的长度值：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">       Stream.of(<span class="string">"hello"</span>,<span class="string">"FunctionalInterface"</span>)</span><br><span class="line">                .map(e-&gt;e.length())</span><br><span class="line">                .forEach(System.out::println);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</li>
</ol>
<ol start="2">
<li><p>运算操作：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">FunctionTest</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span>&#123;</span><br><span class="line">        Function&lt;Integer, Integer&gt; square = integer -&gt; integer * integer; <span class="comment">//定义平方运算</span></span><br><span class="line"></span><br><span class="line">        List&lt;Integer&gt; list = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        list.add(<span class="number">1</span>);</span><br><span class="line">        list.add(<span class="number">2</span>);</span><br><span class="line">        list.add(<span class="number">3</span>);</span><br><span class="line">        list.add(<span class="number">4</span>);</span><br><span class="line"></span><br><span class="line">        list.stream()</span><br><span class="line">                .map(square.andThen(square)) <span class="comment">//四次方</span></span><br><span class="line">                .forEach(System.out::println);</span><br><span class="line">        System.out.println(<span class="string">"------"</span>);</span><br><span class="line"></span><br><span class="line">        list.stream()</span><br><span class="line">                .map(square.compose(e -&gt; e - <span class="number">1</span>)) <span class="comment">//减一再平方</span></span><br><span class="line">                .forEach(System.out::println);</span><br><span class="line">        System.out.println(<span class="string">"------"</span>);</span><br><span class="line"></span><br><span class="line">        list.stream().map(square.andThen(square.compose(e-&gt;e/<span class="number">2</span>))) <span class="comment">//先平方然后除2再平方</span></span><br><span class="line">                .forEach(System.out::println);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>运算结果：</p>
<figure class="highlight tex"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">1</span><br><span class="line">16</span><br><span class="line">81</span><br><span class="line">256</span><br><span class="line">------</span><br><span class="line">0</span><br><span class="line">1</span><br><span class="line">4</span><br><span class="line">9</span><br><span class="line">------</span><br><span class="line">0</span><br><span class="line">4</span><br><span class="line">16</span><br><span class="line">64</span><br></pre></td></tr></table></figure>



</li>
</ol>
<h4 id="Operator-1"><a href="#Operator-1" class="headerlink" title="Operator"></a>Operator</h4><ol>
<li><p>BinaryOperator</p>
<p>找出最大值</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BinaryOperatorTest</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        Stream.of(<span class="number">2</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">1</span>)</span><br><span class="line">            .reduce(BinaryOperator.maxBy(Comparator.comparingInt(Integer::intValue)))</span><br><span class="line">            .ifPresent(System.out::println);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</li>
</ol>
<ol start="2">
<li><p>IntOperator</p>
<p>累加功能：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BinaryOperatorTest</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        IntBinaryOperator intBinaryOperator = (e1, e2)-&gt;e1+e2; <span class="comment">//定义求和二元操作</span></span><br><span class="line">        IntStream.of(<span class="number">2</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">1</span>)</span><br><span class="line">                .reduce(intBinaryOperator).ifPresent(System.out::println);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</li>
</ol>
<h4 id="Predicate-1"><a href="#Predicate-1" class="headerlink" title="Predicate"></a>Predicate</h4><p>筛选出大于0的数中，最小的数：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        IntStream.of(<span class="number">200</span>,<span class="number">45</span>,<span class="number">89</span>,<span class="number">10</span>,-<span class="number">200</span>,<span class="number">78</span>,<span class="number">94</span>)</span><br><span class="line">                .filter(e-&gt;e&gt;<span class="number">0</span>) <span class="comment">//过滤小于0的数</span></span><br><span class="line">                .sorted() <span class="comment">//自然顺序排序</span></span><br><span class="line">                .limit(<span class="number">2</span>) <span class="comment">//取前两个</span></span><br><span class="line">                .forEach(System.out::println);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="Supplier-1"><a href="#Supplier-1" class="headerlink" title="Supplier"></a>Supplier</h4><p>一直生产数据，使用limit限制生产次数：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        Stream.generate(()-&gt;<span class="number">2</span>)</span><br><span class="line">                .limit(<span class="number">10</span>)</span><br><span class="line">                .forEach(System.out::println);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p>​    Java8的Stream 基本上都是使用util.function包下的函数式接口来实现函数式编程的，而函数式接口主要只分为 Function、Operator、Consumer、Predicate、Supplier 这五大类；本文主要只介绍了这五类接口的简单用法，只要能理解掌握最基础的五大类用法，其他变种也能触类旁通。</p>

      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java/" rel="tag">Java</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%87%BD%E6%95%B0%E5%BC%8F%E6%8E%A5%E5%8F%A3/" rel="tag">函数式接口</a></li></ul>


    </footer>

  </div>

  

  
  
  

  

</article>
    
    <article id="post-ElasticSearch操作详解" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/05/20/ElasticSearch%E6%93%8D%E4%BD%9C%E8%AF%A6%E8%A7%A3/"
    >ElasticSearch操作详解</a
  >
</h2>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/05/20/ElasticSearch%E6%93%8D%E4%BD%9C%E8%AF%A6%E8%A7%A3/" class="article-date">
  <time datetime="2020-05-20T11:02:18.000Z" itemprop="datePublished">2020-05-20</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/SpringBoot/">SpringBoot</a>
  </div>

      
      
      
    </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h1 id="ElasticSearch"><a href="#ElasticSearch" class="headerlink" title="ElasticSearch"></a>ElasticSearch</h1><h2 id="基本信息"><a href="#基本信息" class="headerlink" title="基本信息"></a>基本信息</h2><h3 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h3><p>ElasticSearch 是一个基于 Lucene 的搜索服务器。它提供了一个分布式多员工能力的全文搜索引擎，基于 RESTful web 接口。Elasticsearch 是用 Java 语言开发的，并作为 Apache 许可条款下的开放源码发布，是一种流行的企业级搜索引擎。</p>
<p>ElasticSearch 用于云计算中，能够达到实时搜索，稳定，可靠，快速，安装使用方便。</p>
<h3 id="特性"><a href="#特性" class="headerlink" title="特性"></a>特性</h3><ul>
<li>分布式的文档存储引擎</li>
<li>分布式的搜索引擎和分析引擎</li>
<li>分布式，支持PB级数据</li>
</ul>
<h3 id="使用场景"><a href="#使用场景" class="headerlink" title="使用场景"></a>使用场景</h3><ul>
<li>搜索领域</li>
<li>门户网站</li>
<li>广告推广</li>
<li>信息采集</li>
</ul>

      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ElasticSearch/" rel="tag">ElasticSearch</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/SpringBoot/" rel="tag">SpringBoot</a></li></ul>


    </footer>

  </div>

  

  
  
  

  

</article>
    
    <article id="post-推荐一个论文查重的网站" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/05/16/%E6%8E%A8%E8%8D%90%E4%B8%80%E4%B8%AA%E8%AE%BA%E6%96%87%E6%9F%A5%E9%87%8D%E7%9A%84%E7%BD%91%E7%AB%99/"
    >推荐一个论文查重的网站</a
  >
</h2>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/05/16/%E6%8E%A8%E8%8D%90%E4%B8%80%E4%B8%AA%E8%AE%BA%E6%96%87%E6%9F%A5%E9%87%8D%E7%9A%84%E7%BD%91%E7%AB%99/" class="article-date">
  <time datetime="2020-05-16T06:43:53.000Z" itemprop="datePublished">2020-05-16</time>
</a>
      
      
      
      
    </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h2 id="推荐大家一个靠谱的论文检测平台。"><a href="#推荐大家一个靠谱的论文检测平台。" class="headerlink" title="推荐大家一个靠谱的论文检测平台。"></a>推荐大家一个靠谱的论文检测平台。</h2><p>重复的部分有详细出处以及具体修改意见，能直接在文章上做修改，全部改完一键下载就搞定了。他们现在正在做毕业季活动， 赠送很多免费字数，可以说是十分划算了！</p>
<p>地址是：<a href="https://www.paperpass.com/" target="_blank" rel="noopener">https://www.paperpass.com/</a></p>

      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/paperPass/" rel="tag">paperPass</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E8%AE%BA%E6%96%87%E6%9F%A5%E9%87%8D/" rel="tag">论文查重</a></li></ul>


    </footer>

  </div>

  

  
  
  

  

</article>
    
    <article id="post-开发中的实用技巧" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/05/14/%E5%BC%80%E5%8F%91%E4%B8%AD%E7%9A%84%E5%AE%9E%E7%94%A8%E6%8A%80%E5%B7%A7/"
    >开发中的实用技巧</a
  >
</h2>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/05/14/%E5%BC%80%E5%8F%91%E4%B8%AD%E7%9A%84%E5%AE%9E%E7%94%A8%E6%8A%80%E5%B7%A7/" class="article-date">
  <time datetime="2020-05-14T04:18:47.000Z" itemprop="datePublished">2020-05-14</time>
</a>
      
      
      
      
    </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      
      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      

    </footer>

  </div>

  

  
  
  

  

</article>
    
    <article id="post-Git查看代码贡献量" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/05/13/Git%E6%9F%A5%E7%9C%8B%E4%BB%A3%E7%A0%81%E8%B4%A1%E7%8C%AE%E9%87%8F/"
    >Git查看代码贡献量</a
  >
</h2>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/05/13/Git%E6%9F%A5%E7%9C%8B%E4%BB%A3%E7%A0%81%E8%B4%A1%E7%8C%AE%E9%87%8F/" class="article-date">
  <time datetime="2020-05-13T13:58:14.000Z" itemprop="datePublished">2020-05-13</time>
</a>
      
      
      
      
    </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      
      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      

    </footer>

  </div>

  

  
  
  

  

</article>
    
    <article id="post-关于同校问答平台" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/04/19/%E5%85%B3%E4%BA%8E%E5%90%8C%E6%A0%A1%E9%97%AE%E7%AD%94%E5%B9%B3%E5%8F%B0/"
    >关于同校问答平台</a
  >
</h2>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/04/19/%E5%85%B3%E4%BA%8E%E5%90%8C%E6%A0%A1%E9%97%AE%E7%AD%94%E5%B9%B3%E5%8F%B0/" class="article-date">
  <time datetime="2020-04-19T14:37:02.000Z" itemprop="datePublished">2020-04-19</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E6%AF%95%E4%B8%9A%E8%AE%BE%E8%AE%A1/">毕业设计</a>
  </div>

      
      
      
    </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h1 id="关于：同校互助问答平台"><a href="#关于：同校互助问答平台" class="headerlink" title="关于：同校互助问答平台"></a>关于：同校互助问答平台</h1><h2 id="项目简介"><a href="#项目简介" class="headerlink" title="项目简介"></a>项目简介</h2><p>​    整个系统分为三个部分：<code>前端前台用户系统</code>、<code>前端后台管理系统</code>和<code>后端实现</code>。</p>
<p>​    系统采用前后端分离架构，前端采用vue框架开发，elementUI实现页面组件化设计和渲染，后端采用Java语言搭建Springboot项目，集成Mybatis连接和操作数据库，数据持久化方面使用MySQL数据库存储持久化数据,MongoDB以文档的形式存储数据，数据库可视化工具使用Navicat方便、快捷地操作数据库中地数据。本系统设计能够给在校以及已毕业的同校校友相互之间提供高效、直接的联系以及问答咨询。</p>
<h2 id="开发环境"><a href="#开发环境" class="headerlink" title="开发环境"></a>开发环境</h2><h3 id="1-前端：Vue、ElementUI"><a href="#1-前端：Vue、ElementUI" class="headerlink" title="1.前端：Vue、ElementUI"></a>1.前端：Vue、ElementUI</h3><p>​        Vue是一套用于构建用户界面的渐进式JavaScript框架，Vue设计为可自底而上逐层应用，为开发者提供了响应式和组件化的视图组件，Vue在API和设计方面比较简单，容易上手。</p>
<blockquote>
<p>Vue不仅易于上手，而且方便和第三方库或者既有项目进行整合。</p>
<p>ElementUI是与Vue对应的一个UI组件库，方便开发者使用对应的UI组件进行快速开发。</p>
</blockquote>
<h4 id="相关工具或技术"><a href="#相关工具或技术" class="headerlink" title="相关工具或技术"></a>相关工具或技术</h4><ul>
<li><strong>密码加密</strong>：对用户密码进行<strong>MD5不对称加密</strong>，再传输给后端进行信息检验或保存</li>
</ul>
<h3 id="2-后端：Springboot"><a href="#2-后端：Springboot" class="headerlink" title="2.后端：Springboot"></a>2.后端：Springboot</h3><p>Java语言，一门经典的静态语言，作为静态面向对象编程语言的代表，它很好地实现了面向对象的理论，不仅吸收了C++语言的各种优点，还摒弃了C++中较难理解的指针和多继承等概念，从Java发布至今20多年来，一直迸发着活跃的生命力和新的活力。</p>
<blockquote>
<p>​        2014年Pivotal团队基于Maven整合了前人所开发的几乎所有框架，发布了一个全新的轻量级框架——SpringBoot。</p>
</blockquote>
<p>​    SpringBoot继承了Spring框架原有的优秀特性，还简化了Spring应用的初始化搭建和开发过程；SpringBoot提供了很多框架的默认配置和使用方式，约定大于配置，减少了很多配置工作，能够帮助我们快捷、方便地搭建和开发Java项目，也为之后Java在微服务架构开发方向的发展奠定了基石。</p>
<p>​    本项目的后端总体上采用SpringBoot集成SSM进行开发。</p>
<h4 id="相关工具或技术-1"><a href="#相关工具或技术-1" class="headerlink" title="相关工具或技术"></a>相关工具或技术</h4><ul>
<li><strong>FastDFS</strong>：<strong>分布式文件服务器</strong>。通过FastDFS，可以实现图片的上传操作，将图片上传至云服务器，实现文章、问题以及回答信息等数据可以实现用户上传图片。</li>
<li><strong>定时器</strong>：后端通过<strong>注解</strong>实现定时器功能。实现每天用户一天举报次数归零、定时统计各个学校用户数量等功能，对性能损耗较小。</li>
<li><strong>JWT</strong>：生成token信息保存进请求头中，并返回给前端。</li>
</ul>
<h3 id="3-数据库：MySQL、MongoDB"><a href="#3-数据库：MySQL、MongoDB" class="headerlink" title="3.数据库：MySQL、MongoDB"></a>3.数据库：MySQL、MongoDB</h3><p>数据持久化存储方式按照数据自身的特性，将不同的数据分别存储于MySQL以及MongoDB之中，其中MySQL主要保存<code>用户账号相关信息数据</code>、<code>管理员账号信息数据</code>、<code>学校相关信息</code>等；MongoDB主要保存<code>平台文章相关信息数据</code>、<code>平台问题相关信息数据</code>、<code>相关的草稿数据</code>以及<code>用户平台相关信息数据</code>。</p>
<p>① MySQL数据库</p>
<p>​        MySQL是当前最流行的关系型数据库管理系统之一，关系数据库将数据保存在不同的表中，并没有把数据都放在一个大仓库中，极大提高了速度和灵活性。</p>
<blockquote>
<p>​        相对于其他关系型数据库管理系统，MySQL还具有安装配置简便、体积小、速度快、拥有成本低等特点，而且源码开放，中小型网站的开发一般都选择MySQL作为网站数据库。</p>
</blockquote>
<p>② MongoDB数据库</p>
<p>​        MongoDB是一个基于分布式文件存储的、由C++语言编写的数据库，为WEB应用提供可扩展的高性能数据存储解决方案，此外还具有易部署、易使用、存储数据非常方便的特点。</p>
<blockquote>
<p>​        MongoDB是一个NoSQL数据库，也是一个介于关系数据库和非关系数据库之间的产品，是非关系数据库之中功能最多，而且最像传统的关系型数据库的NoSQL数据库。</p>
</blockquote>

      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ElementUI/" rel="tag">ElementUI</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java/" rel="tag">Java</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/MongoDB/" rel="tag">MongoDB</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/MySql/" rel="tag">MySql</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Springboot/" rel="tag">Springboot</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Vue/" rel="tag">Vue</a></li></ul>


    </footer>

  </div>

  

  
  
  

  

</article>
    
    <article id="post-毕设项目开发笔记" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/04/19/%E6%AF%95%E8%AE%BE%E9%A1%B9%E7%9B%AE%E5%BC%80%E5%8F%91%E7%AC%94%E8%AE%B0/"
    >毕设项目开发笔记</a
  >
</h2>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/04/19/%E6%AF%95%E8%AE%BE%E9%A1%B9%E7%9B%AE%E5%BC%80%E5%8F%91%E7%AC%94%E8%AE%B0/" class="article-date">
  <time datetime="2020-04-19T14:35:14.000Z" itemprop="datePublished">2020-04-19</time>
</a>
      
      
      
      
    </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h2 id="遇到的问题"><a href="#遇到的问题" class="headerlink" title="遇到的问题"></a>遇到的问题</h2><ul>
<li><p>java.lang.NoSuchMethodError: org.apache.commons.io</p>
</li>
<li><p>mavon-editor的图片上传问题</p>
</li>
<li><p>org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field xxx exceeds its maximum permitted size of 1048576 bytes.</p>
</li>
</ul>

      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ElementUI/" rel="tag">ElementUI</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/FastDFS/" rel="tag">FastDFS</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Springboot/" rel="tag">Springboot</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Vue/" rel="tag">Vue</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%AF%95%E4%B8%9A%E8%AE%BE%E8%AE%A1/" rel="tag">毕业设计</a></li></ul>


    </footer>

  </div>

  

  
  
  

  

</article>
    
    <article id="post-Springboot整合Swagger-ui报错" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h2 itemprop="name">
  <a class="article-title" href="/2020/03/14/Springboot%E6%95%B4%E5%90%88Swagger-ui%E6%8A%A5%E9%94%99/"
    >Springboot整合Swagger-ui报错</a
  >
</h2>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/03/14/Springboot%E6%95%B4%E5%90%88Swagger-ui%E6%8A%A5%E9%94%99/" class="article-date">
  <time datetime="2020-03-14T14:42:46.000Z" itemprop="datePublished">2020-03-14</time>
</a>
      
      
      
      
    </div>
    

    

    <div class="article-entry" itemprop="articleBody">
      


      

      
      <h2 id="Swagger报错：Unable-to-infer-base-url"><a href="#Swagger报错：Unable-to-infer-base-url" class="headerlink" title="Swagger报错：Unable to infer base url"></a>Swagger报错：Unable to infer base url</h2><p>在进入Swagger接口测试界面时，弹出一个弹窗，内容是：Unable to infer base url. ……</p>
<p>大体的意思为：Swagger获取不到它需要的资源，原因可以从两方面考虑：</p>
<ul>
<li><p><strong>Swagger相关的配置没配置好</strong>。这种情况相关配置教程很多，请用自己喜欢的引擎搜索</p>
</li>
<li><p><strong>Swagger没有获得访问路径的权限。</strong>例如之前刚配置好的权限管理，如Shiro、Security等，需要对Swagger请求访问的相关路径进行开放。相关路径如下：</p>
<ul>
<li>/swagger-ui.html</li>
<li>/webjars/**</li>
<li>/v2/**</li>
<li>/swagger-resources/**</li>
</ul>
<p>eg:在Shiro中配置开发相关路径：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootConfiguration</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyWebConfiguration</span> <span class="keyword">implements</span> <span class="title">WebMvcConfigurer</span></span>&#123;</span><br><span class="line">    <span class="comment">//······</span></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addInterceptors</span><span class="params">(InterceptorRegistry registry)</span> </span>&#123;</span><br><span class="line">        registry.addInterceptor(getLoginInterceptor())</span><br><span class="line">                .addPathPatterns(<span class="string">"/**"</span>)</span><br><span class="line">                .excludePathPatterns(<span class="string">"/"</span>)</span><br><span class="line">                .excludePathPatterns(<span class="string">"/user/register"</span>)</span><br><span class="line">                .excludePathPatterns(<span class="string">"/user/login"</span>)</span><br><span class="line">                .excludePathPatterns(<span class="string">"/swagger-ui.html"</span>)</span><br><span class="line">                .excludePathPatterns(<span class="string">"/webjars/**"</span>)</span><br><span class="line">                .excludePathPatterns(<span class="string">"/v2/**"</span>)</span><br><span class="line">                .excludePathPatterns(<span class="string">"/swagger-resources/**"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//······</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>

      
      <!-- reward -->
      
    </div>
      <!-- copyright -->
      
    <footer class="article-footer">
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Springboot/" rel="tag">Springboot</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Swagger-UI/" rel="tag">Swagger-UI</a></li></ul>


    </footer>

  </div>

  

  
  
  

  

</article>
    
  </article>
  

  
  <nav class="page-nav">
    
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><a class="page-number" href="/page/3/">3</a><span class="space">&hellip;</span><a class="page-number" href="/page/6/">6</a><a class="extend next" rel="next" href="/page/2/">下一页</a>
  </nav>
  
</section>
</div>

      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2019-2020
        LinPaiBin
      </li>
      <li>
        
          Powered by
        
        
        <a href="https://hexo.io" target="_blank">Hexo</a> Theme <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
    <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
      <aside class="sidebar">
        <button class="navbar-toggle"></button>
<nav class="navbar" style="opacity: 0.5;">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="滨书"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/%E7%94%9F%E6%B4%BB/">生活</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/12/02/AboutMe">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
      </aside>
      <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
      
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/jquery.justifiedGallery.min.js"></script>


<script src="/js/lazyload.min.js"></script>


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<script src="/js/share.js"></script>



<script src="/fancybox/jquery.fancybox.min.js"></script>




<script>
  try {
    var typed = new Typed("#subtitle", {
    strings: ['人生如棋，吾愿为卒','愿你一生努力，一生无憾','不求事事顺意，但求无愧于心'],
    startDelay: 0,
    typeSpeed: 250,
    loop: true,
    backSpeed: 100,
    showCursor: true
    });
  } catch (err) {
  }
  
</script>




<script>
  var ayerConfig = {
    mathjax: false
  }
</script>


<script src="/js/ayer.js"></script>


<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>




<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>
  </div>
</body>

</html>